/**
 * withPerm指令，判断当前用户是否有某个操作的权限
 */

import store from "@/store/store.js";

export default {
    mounted(el, binding, vnode) {
        const {value} = binding
        //当前用户的所有权限
        const userPermissionList = store.state.user.permissionList
        if (value && value instanceof Array && value.length > 0) {
            const aimPermission = value
            const show = userPermissionList.some(permission => {
                return aimPermission.indexOf(permission) > -1;
            })
            if (!show) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error(`请设置操作权限标签值`)
        }
    }
}
